<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	
		<title><?php echo C('WEB_TITLE');?></title>
	
	<link rel="stylesheet" type="text/css" href="../Public/css/base.css" media="all">
	<link rel="stylesheet" type="text/css" href="../Public/css/module.css">
	<link rel="stylesheet" type="text/css" href="../Public/css/style.css" media="all">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/artDialog/skins/default.css">
	<script type="text/javascript" src="__PUBLIC__/Js/jquery.js"></script>
	<script type="text/javascript" src="__PUBLIC__/Js/artDialog/jquery.artDialog.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/Js/artDialog/artDialog.plugins.min.js"></script>
	<script type="text/javascript" src="../Public/js/common.js"></script>
	<?php if(in_array((ACTION_NAME), explode(',',"add,edit"))): ?><script type="text/javascript" src="__PUBLIC__/Js/ValidForm.js"></script><?php endif; ?>
	
	<script type="text/javascript" src="__PUBLIC__/uploadify/jquery.uploadify.min.js"></script>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/uploadify/uploadify.css">

	<script type="text/javascript">
        var URL	   ='__URL__';
        var PUBLIC = "../Public/";
    </script>
</head>
<body style="padding:0;">
	
	<div id="main-content">
		<div id="top-alert" class="fixed alert alert-error" style="display: none;">
			<button class="close fixed" style="margin-top: 4px;">&times;</button>
			<div class="alert-content">这是内容</div>
		</div>
		<div id="main" class="main">
			
	<style type="text/css">
		.item{display: inline-block;width: 310px;height: 235px;overflow: hidden;position: relative;}
		.item img{width: 300px;}
		.item .odiv{background: #ccc;display: none;}
		.item h3{background: #333;color: white;position: absolute;height: 25px;top: 210px;width: 300px;}
		.item span{position: absolute;top: 100px;left: 145px;}
		.item span a{text-decoration: none;}
	</style>
	<div class="main-title">
		<h2>七牛文件管理</h2>
	</div>
	<div class="cf">
		<div class="fl">
			<input id="file_upload" name="file" type="file" multiple="true">
			<div id="queue"></div>
		</div>
	</div>
	<div class="data-table table-striped" id="ImageView">
		<?php if(is_array($list)): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><div class="item" id="Item<?php echo ($vo["id"]); ?>">
				<img src="<?php echo ($vo["savepath"]); echo ($vo["savename"]); ?>" alt="<?php echo ($vo["name"]); ?>"/>
				<div class="odiv">
					<h3><?php echo ($vo["name"]); ?></h3>
					<span><a href="javascript:delPhoto(<?php echo ($vo["id"]); ?>);" class="btn">删除</a></span>
				</div>
			</div><?php endforeach; endif; else: echo "" ;endif; ?>
	</div>
	<div class="page"><div><?php echo ($page); ?></div></div>

		</div>
		<!-- <div class="cont-ft">
			<div class="copyright">
				<div class="fl">感谢使用<a href="http://www.onethink.cn" target="_blank">OneThink</a>管理平台</div>
				<div class="fr">V1.0.131129</div>
			</div>
		</div> -->
	</div>
	<script type="text/javascript">
        +function(){
            var $window = $(window), $subnav = $("#subnav"), url;
            $window.resize(function(){
                $("#main").css("min-height", $window.height() - 130);
            }).resize();
            $("#subnav h3 a").click(function(e){e.stopPropagation()});
	        /* 表单获取焦点变色 */
	        $("form").on("focus", "input", function(){
		        $(this).addClass('focus');
	        }).on("blur","input",function(){
				        $(this).removeClass('focus');
			        });
		    $("form").on("focus", "textarea", function(){
			    $(this).closest('label').addClass('focus');
		    }).on("blur","textarea",function(){
			    $(this).closest('label').removeClass('focus');
		    });
            // 导航栏超出窗口高度后的模拟滚动条
            var sHeight = $(".sidebar").height();
            var subHeight  = $(".subnav").height();
            var diff = subHeight - sHeight; //250
            var sub = $(".subnav");
            if(diff > 0){
                $(window).mousewheel(function(event, delta){
                    if(delta>0){
                        if(parseInt(sub.css('marginTop'))>-10){
                            sub.css('marginTop','0px');
                        }else{
                            sub.css('marginTop','+='+10);
                        }
                    }else{
                        if(parseInt(sub.css('marginTop'))<'-'+(diff-10)){
                            sub.css('marginTop','-'+(diff-10));
                        }else{
                            sub.css('marginTop','-='+10);
                        }
                    }
                });
            }
        }();
		//搜索功能
		$("#search").click(function(){
			var url = $(this).attr('url');
	        var query  = $('.search-form').find('input').serialize();
	        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
	        query = query.replace(/^&/g,'');
	        if( url.indexOf('?')>0 ){
	            url += '&' + query;
	        }else{
	            url += '?' + query;
	        }
			window.location.href = url;
		});
		//回车搜索
		$(".search-input").keyup(function(e){
			if(e.keyCode === 13){
				$("#search").click();
				return false;
			}
		});
		$(function(){
			$('.row td:gt(0)').attr('nowrap','');
			$('.row th:gt(0)').attr('nowrap','');
			$('.row:gt(0)').click(function(e){
				if(e.target.name!='key'){
					// && !e.target.href
					var xx=$(this).find(':checkbox');
					xx.attr('checked',!xx.attr('checked'));
				}
			});
			$('.Abstruct').each(function(){
				if ($(this).attr('type')=='img'){
					var src=$(this).html();
					$(this).click(function(){
						$.dialog({ 
							title:'查看图片',
							content: src+'<br><img src="'+src+'" />'
						}); 
					});
				}else{
					var src=$(this).html();
					$(this).click(function(){
						$.dialog({ 
							title:'查看详细',
							content: eval(src)
						}); 
					});
				}
				$(this).attr('title',$(this).html());
			});

		})
	</script>
	
	<script>
		function delPhoto(id){
			get('__URL__/delete/id/'+id,function(){ $('#Item'+id).remove();});
		}
		$('.item').hover(
			function(){ $(this).find('.odiv').show();},
			function(){ $(this).find('.odiv').hide();}
		);
		function getFileName(){
			var d=new Date();
			var filename=d.getTime();
			return filename;
		}
		$(function() {
			var filetype = null;
			var filename=getFileName();//'<?php echo getUploadName();?>';
			var now=new Date();
			$('#file_upload').uploadify({
				'onSelect' : function(file){
					filetype = file.type;
					$('#file_upload').uploadify('settings', 'formData', {"key":filename+filetype}) //上传文件的名称
                },
				'fileObjName' : 'file',  //七牛的上传的字段名称是file
				'formData'     : {
                    'token'     : '<?php echo ($upToken); ?>', //token
                },
				
				'buttonText'  : '选择文件',
				'swf'      : '__PUBLIC__/uploadify/uploadify.swf',
				'uploader' : 'http://up.qiniu.com/',
				'method'   : 'POST',
				'onUploadSuccess' : function(file, data, response) {
					//console.info(file);
					data=$.parseJSON(data);
					//console.info(data);
                    if(data.key!==""){
                    	$.ajax({
                    		url:'__URL__/saveAttach',
                    		data:'savename='+data.key+'&size='+file.size+'&name='+file.name+'&hash='+data.hash+'&extension='+file.type.replace('.',''),
                    		type:'POST'
                    	});
                    	var html='<div class="item"><img src="http://sssui.u.qiniudn.com/'+data.key+'" alt="'+file.name+'"/><div class="odiv"><h3>'+file.name+'</h3></div></div>';
						$("#ImageView").prepend(html);
					}else{
						alert("<font style='color:red;bolid;font:700 14px Arial, Helvetica, sans-serif;'>上传失败，请联系管理员！</font>");
					}
                 },
			});
		});
	</script>

</body>
</html>